Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbpf-tools/profile: Add support for PID-namespacing #5152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ekyooo
Copy link
Contributor

@ekyooo ekyooo commented Nov 21, 2024

Support PID namespace translation as memleak.py does.

Copy link
Contributor

@eiffel-fl eiffel-fl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have few comments, but it is looking really good!

@@ -595,6 +610,8 @@ int main(int argc, char **argv)
env.perf_max_stack_depth * sizeof(unsigned long));
bpf_map__set_max_entries(obj->maps.stackmap, env.stack_storage_size);

set_pidns(obj);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can catch the returned value and show a warning message in case PID namespace does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. thank you.

Comment on lines 532 to 515
if (kernel_at_least(5, 7))
return -EPERM;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with fixed version check is that they will not work on kernel where a specific patch could have been backported.
Is there a way to rather check for the existence of a given bpf helper?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In bcc/tools, we have a few cases (including profile) checking kernel version for bpf_get_ns_current_pid_tgid() availability. But for libbpf-tools, I think we can do better.
See trace_helpers.c. There are a few probe_*() functions which tries to detect whether a particular feature (prog_type, map_type) is supported or not. I think we can have another probe function to check whether bpf_get_ns_current_pid_tgid() is supported or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for good feedback.
I have applied the opinion.

@eiffel-fl
Could you please check if it's what you want?

Thank you.

@@ -595,6 +631,10 @@ int main(int argc, char **argv)
env.perf_max_stack_depth * sizeof(unsigned long));
bpf_map__set_max_entries(obj->maps.stackmap, env.stack_storage_size);

err = set_pidns(obj);
if (err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us do 'err && env.verbose' here. We want to print out the below information under verbose mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's modified. thank you.

Comment on lines 532 to 515
if (kernel_at_least(5, 7))
return -EPERM;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In bcc/tools, we have a few cases (including profile) checking kernel version for bpf_get_ns_current_pid_tgid() availability. But for libbpf-tools, I think we can do better.
See trace_helpers.c. There are a few probe_*() functions which tries to detect whether a particular feature (prog_type, map_type) is supported or not. I think we can have another probe function to check whether bpf_get_ns_current_pid_tgid() is supported or not.

Add PID translation for nested PID namespace environments, such as container.
…he kernel

Support PID namespace mapping only in kernels where bpf_get_ns_current_pid_tgid
is available.

Add a utility function to check if bpf_get_ns_current_pid_tgid is available in
the target kernel. Use this function in the profile to determine support for PID
namespace mapping.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants